import { formartTime } from "@/utils/timeFormart";
import { list } from "@/api/Order/Order.api";
export default {
    namespaced: true,
    state() {
        //     return {
        //         orderFormData:{},
        //         orderList:[],
        //         currentPage:1,
        //         pageSize:10
        //     }

        return {
            tableList: [],
            currentPage: 1,
            pageSize: 10,
            total: 0
        }
    },

    getters: {
        updateTableList(state) {
            return state.tableList.map(item => {
                item.orderTime = formartTime(item.orderTime)
                item.deliveryTime = formartTime(item.deliveryTime)
                return item
            })
        },
    },

    mutations: {


        // // 更新orderFormData
        // UPDATE_ORDER_FORM_DATA(state,payload){
        //     state.orderFormData = Object.assign({},payload)
        // },

        update_tableList(state, payload) {
            state.tableList = [...payload]
        },
        //更新currentPage
        update_currentPage(state, payload) {
            state.currentPage = payload
        },
        //更新pageSize
        update_pageSize(state, payload) {
            state.pageSize = payload
        },
        //更新total
        update_total(state, payload) {
            state.total = payload
        }
        // // 更新orderList
        // UPDATE_ORDER_LIST(state,payload){
        //     state.orderList = [...payload]
        // }
    },

    actions: {
        sync_update_tableList({ state, commit }) {
            let { currentPage, pageSize } = state
            list({ currentPage, pageSize }).then(res => {
                commit('update_tableList', res.data.data)
                commit('update_total', res.data.total)
                console.log(res);

            })
        }

        // SYNC_ORDER_LIST({state,commit}){
        //     let {currentPage,pageSize} = state
        //     list({
        //         currentPage,
        //         pageSize,
        //       }).then((res) => {
        //         commit('UPDATE_ORDER_LIST',res.data.data)
        //       });
        // }
    }

}